<?php
echo $header;
echo $column_left;
echo $column_right;
$width_content = '98%';
if (($column_left) && ($column_right)) {
    $width_content = '48%';
} elseif (($column_left) || ($column_right)) {
    $width_content = '73%';
}
?>
<div class="content" style="width:<?php echo $width_content; ?>"><?php echo $content_top; ?>
    <div class="breadcrumb">
        <?php foreach ($breadcrumbs as $breadcrumb) { ?>
            <?php echo $breadcrumb['separator']; ?><a href="<?php echo $breadcrumb['href']; ?>"><?php echo $breadcrumb['text']; ?></a>
        <?php } ?>
    </div>
    <ul data-role="listview" data-divider-theme="a" data-inset="true">
        <li data-role="list-divider"><h1><?php echo $heading_title; ?></h1></li>
    </ul><br />
    <?php if ($error_warning) { ?>
        <div class="warning"><?php echo $error_warning; ?></div>
    <?php } ?>
    <p><?php echo $text_account_already; ?></p>
    <form action="<?php echo $action; ?>" method="post" enctype="multipart/form-data" id="register">
        <div class="form">
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_your_details; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_firstname; ?>" type="text" name="firstname" value="<?php echo $firstname; ?>" /><span class="required">*</span>
                        <?php if ($error_firstname) { ?>
                            <div class="error"><?php echo $error_firstname; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_lastname; ?>" type="text" name="lastname" value="<?php echo $lastname; ?>" /><span class="required">*</span>
                        <?php if ($error_lastname) { ?>
                            <div class="error"><?php echo $error_lastname; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_email; ?>" type="text" name="email" value="<?php echo $email; ?>" /><span class="required">*</span>
                        <?php if ($error_email) { ?>
                            <div class="error"><?php echo $error_email; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_telephone; ?>" type="text" name="telephone" value="<?php echo $telephone; ?>" /><span class="required">*</span>
                        <?php if ($error_telephone) { ?>
                            <div class="error"><?php echo $error_telephone; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_fax; ?>" type="text" name="fax" value="<?php echo $fax; ?>" />
                    </li>
                </ul>
            </div>
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_your_address; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_company; ?>" type="text" name="company" value="<?php echo $company; ?>" /><span class="required">*</span>
                    </li>
                    <li style="display:<?php echo (count($customer_groups) > 1 ? 'block' : 'none') ?>;">
                        <fieldset data-role="controlgroup">
                            <legend><?php echo $entry_customer_group; ?></legend>
                            <?php foreach ($customer_groups as $customer_group) : ?>
                                <input type="radio" name="customer_group_id" id="customer_group_id<?php echo $customer_group['customer_group_id'] ?>" value="<?php echo $customer_group['customer_group_id'] ?>" <?php if ($customer_group['customer_group_id'] == $customer_group_id) : ?>checked="checked" <?php endif ?>/>
                                <label for="customer_group_id<?php echo $customer_group['customer_group_id'] ?>"><?php echo $customer_group['name'] ?></label>
                            <?php endforeach ?>
                        </fieldset>
                    </li>
                    <li id="company-id-display">
                        <input placeholder="<?php echo $entry_company_id; ?>" type="text" name="company_id" value="<?php echo $company_id; ?>" /><span id="company-id-required" class="required">*</span>
                        <?php if ($error_company_id) { ?>
                            <div class="error"><?php echo $error_company_id; ?></div>
                        <?php } ?>
                    </li>
                    <li id="tax-id-display">
                        <input placeholder="<?php echo $entry_tax_id; ?>" type="text" name="tax_id" value="<?php echo $tax_id; ?>" /><span id="tax-id-required" class="required">*</span>
                        <?php if ($error_tax_id) { ?>
                            <div class="error"><?php echo $error_tax_id; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_address_1; ?>" type="text" name="address_1" value="<?php echo $address_1; ?>" /><span class="required">*</span>
                        <?php if ($error_address_1) { ?>
                            <div class="error"><?php echo $error_address_1; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_address_2; ?>" type="text" name="address_2" value="<?php echo $address_2; ?>" /><span class="required">*</span>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_city; ?>" type="text" name="city" value="<?php echo $city; ?>" /><span class="required">*</span>
                        <?php if ($error_city) { ?>
                            <div class="error"><?php echo $error_city; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_postcode; ?>" type="text" name="postcode" value="<?php echo $postcode; ?>" /><span class="required" id="postcode-required">*</span>
                        <?php if ($error_postcode) { ?>
                            <div class="error"><?php echo $error_postcode; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <label for="country_id"><span class="required">*</span> <?php echo $entry_country; ?></label>
                        <select name="country_id" id="country_id" class="large-field">
                            <option value=""><?php echo $text_select; ?></option>
                            <?php foreach ($countries as $country) { ?>
                                <option value="<?php echo $country['country_id']; ?>"<?php echo ($country['country_id'] == $country_id ? ' selected="selected"' : ''); ?>><?php echo $country['name']; ?></option>
                            <?php } ?>
                        </select>
                        <?php if ($error_country) { ?>
                            <div class="error"><?php echo $error_country; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <label for="zone_id"><span class="required">*</span> <?php echo $entry_zone; ?></label>
                        <select name="zone_id" id="zone_id" class="large-field">
                        </select>
                        <?php if ($error_zone) { ?>
                            <div class="error"><?php echo $error_zone; ?></div>
                        <?php } ?>
                    </li>
                </ul>
            </div>
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_your_password; ?></li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_password; ?>" type="password" name="password" value="<?php echo $password; ?>" /><span class="required">*</span>
                        <?php if ($error_password) { ?>
                            <div class="error"><?php echo $error_password; ?></div>
                        <?php } ?>
                    </li>
                    <li>
                        <input class="large-field" placeholder="<?php echo $entry_confirm; ?>" type="password" name="confirm" value="<?php echo $confirm; ?>" /><span class="required">*</span>
                        <?php if ($error_confirm) { ?>
                            <div class="error"><?php echo $error_confirm; ?></div>
                        <?php } ?>
                    </li>
                </ul>
            </div>
            <div data-role="fieldcontain">
                <ul data-role="listview" data-divider-theme="a" data-inset="true">
                    <li data-role="list-divider"><?php echo $text_newsletter; ?></li>
                    <li>
                        <fieldset data-role="controlgroup">
                            <legend><?php echo $entry_newsletter; ?></legend>
                            <label for="newsletter-1"><?php echo $text_yes; ?></label>
                            <?php if ($newsletter == 1) { ?>
                                <input id="newsletter-1" type="radio" name="newsletter" value="1" checked="checked" />
                                <input id="newsletter-0" type="radio" name="newsletter" value="0" />
                            <?php } else { ?>
                                <input id="newsletter-1" type="radio" name="newsletter" value="1" />
                                <input id="newsletter-0" type="radio" name="newsletter" value="0" checked="checked" />
                            <?php } ?>
                            <label for="newsletter-0"><?php echo $text_no; ?></label>
                        </fieldset>
                    </li>
                </ul>
            </div>
        </div>
        <div class="buttons">
            <div class="right">
                <?php if ($text_agree) { ?>
                    <label for="agree">&nbsp;</label><?php echo strtr($text_agree, array('<a' => '<a data-rel="dialog"')); ?>
                    <?php if ($agree) { ?>
                        <input type="checkbox" id="agree" name="agree" value="1" checked="checked" />
                    <?php } else { ?>
                        <input type="checkbox" id="agree" name="agree" value="1" />
                    <?php }
                }
                ?>
                <a data-role="button" onclick="$('#register').submit();" class="button"><span><?php echo $button_continue; ?></span></a>
            </div>
        </div>
    </form>
<?php echo $content_bottom; ?>
</div>
<script type="text/javascript"><!--
$('input[name=\'customer_group_id\']:checked').live('change', function() {
        var customer_group = [];

<?php foreach ($customer_groups as $customer_group) { ?>
            customer_group[<?php echo $customer_group['customer_group_id']; ?>] = [];
            customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_display'] = '<?php echo $customer_group['company_id_display']; ?>';
            customer_group[<?php echo $customer_group['customer_group_id']; ?>]['company_id_required'] = '<?php echo $customer_group['company_id_required']; ?>';
            customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_display'] = '<?php echo $customer_group['tax_id_display']; ?>';
            customer_group[<?php echo $customer_group['customer_group_id']; ?>]['tax_id_required'] = '<?php echo $customer_group['tax_id_required']; ?>';
<?php } ?>

        if (customer_group[this.value]) {
            if (customer_group[this.value]['company_id_display'] == '1') {
                $('#company-id-display').show();
            } else {
                $('#company-id-display').hide();
            }

            if (customer_group[this.value]['company_id_required'] == '1') {
                $('#company-id-required').show();
            } else {
                $('#company-id-required').hide();
            }

            if (customer_group[this.value]['tax_id_display'] == '1') {
                $('#tax-id-display').show();
            } else {
                $('#tax-id-display').hide();
            }

            if (customer_group[this.value]['tax_id_required'] == '1') {
                $('#tax-id-required').show();
            } else {
                $('#tax-id-required').hide();
            }
        }
    });

    $('input[name=\'customer_group_id\']:checked').trigger('change');
    //--></script>
<script type="text/javascript"><!--
    $('select[name=\'country_id\']').bind('change', function() {
        $.ajax({
            url: 'index.php?route=account/register/country&country_id=' + this.value,
            dataType: 'json',
            beforeSend: function() {
                $('select[name=\'country_id\']').after('<span class="wait">&nbsp;<img src="catalog/view/theme/default/image/loading.gif" alt="" /></span>');
            },
            complete: function() {
                $('.wait').remove();
            },
            success: function(json) {
                if (json['postcode_required'] == '1') {
                    $('#postcode-required').show();
                } else {
                    $('#postcode-required').hide();
                }

                html = '<option value=""><?php echo $text_select; ?></option>';

                if (json['zone'] != '') {
                    for (i = 0; i < json['zone'].length; i++) {
                        html += '<option value="' + json['zone'][i]['zone_id'] + '"';

                        if (json['zone'][i]['zone_id'] == '<?php echo $zone_id; ?>') {
                            html += ' selected="selected"';
                        }

                        html += '>' + json['zone'][i]['name'] + '</option>';
                    }
                } else {
                    html += '<option value="0" selected="selected"><?php echo $text_none; ?></option>';
                }

                $('select[name=\'zone_id\']').html(html);
            },
            error: function(xhr, ajaxOptions, thrownError) {
                alert(thrownError + "\r\n" + xhr.statusText + "\r\n" + xhr.responseText);
            }
        });
    });

    $('select[name=\'country_id\']').trigger('change');
    //--></script>
<?php echo $footer; ?>